﻿using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

using PickGold.Handler;

namespace PickGold.Generic
{
	/// <summary>
	/// 步进枚举器
	/// </summary>
	public class StepEnumerable<T> : IEnumerable<T>, IEnumerator<T>, IEnumerable, IEnumerator
	{
		private long _Seed;
		private long _Stop;
		private long _Step;
		private long _Current;

		/// <summary>
		/// 构造一个步进枚举器
		/// </summary>
		/// <param name="seed">种子</param>
		/// <param name="stop">终止</param>
		/// <param name="step">步长，默认为一</param>
		public StepEnumerable(long seed, long stop, long step)
		{
			this._Seed = seed;
			this._Stop = stop;
			this._Step = step;
			this._Current = seed;
		}
		/// <summary>
		/// 构造一个步长为一的步进枚举器
		/// </summary>
		/// <param name="seed">种子</param>
		/// <param name="stop">终止</param>
		public StepEnumerable(long seed, long stop)
		{
			this._Seed = seed;
			this._Stop = stop;
			this._Step = 1;
			this._Current = seed;
		}

		/// <summary>
		/// 种子
		/// </summary>
		public long Seed
		{
			set
			{
				this._Seed = value;
			}
			get
			{
				return this._Seed;
			}
		}

		/// <summary>
		/// 终止
		/// </summary>
		public long Stop
		{
			set
			{
				this._Stop = value;
			}
			get
			{
				return this._Stop;
			}
		}

		/// <summary>
		/// 步长
		/// </summary>
		public long Step
		{
			set
			{
				this._Step = value;
			}
			get
			{
				return this._Step;
			}
		}

		/// <summary>
		/// 当前步
		/// </summary>
		public long Current
		{
			set
			{
				this._Current = value;
			}
			get
			{
				return this._Current;
			}
		}

		object IEnumerator.Current
		{
			get
			{
				return Reflector<T>.DefaultValue;
			}
		}

		bool IEnumerator.MoveNext()
		{
			if (this._Current > this._Stop)
				return false;

			this._Current += this._Step;
			return true;
		}

		void IEnumerator.Reset()
		{
			this._Current = this._Seed;
		}

		IEnumerator IEnumerable.GetEnumerator()
		{
			return new StepEnumerable<T>(this._Seed, this._Stop, this._Step);
		}

		T IEnumerator<T>.Current
		{
			get
			{
				return Reflector<T>.DefaultValue;
			}
		}

		void IDisposable.Dispose()
		{
		}

		IEnumerator<T> IEnumerable<T>.GetEnumerator()
		{
			return new StepEnumerable<T>(this._Seed, this._Stop, this._Step);
		}
	}
}
